<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>售后订单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{ url_for('static',filename='layuiadmin/layui/css/layui.css') }}" media="all">
    <link rel="stylesheet" href="{{ url_for('static',filename='layuiadmin/style/admin.css') }}" media="all">

</head>

<body>


<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">

                    <form class="layui-form" style="padding-bottom: 10px">
                        <div class="layui-input-inline">
                            <input type="text" name="user_id" autocomplete="off"
                                   placeholder="用户手机号" class="layui-input">
                            <input type="hidden" name="status" value="{{ status }}" class="layui-input">
                        </div>

                        <div class="layui-input-inline " style="width: 90px">
                            <button class="layui-btn" id="searchEmailCompany" data-type="reload">
                                <i class="layui-icon" style="font-size: 20px; "></i> 搜索
                            </button>
                        </div>
                    </form>

                    <button class="layui-btn check-layui-btn" data-type="getCheckData">成功</button>
                    <button class="layui-btn layui-btn-danger check-cancel-layui-btn" data-type="getCheckLength">失败
                    </button>
                    <table class="layui-hide" id="test-table" lay-filter="test-table"></table>

                </div>
            </div>
        </div>
    </div>

</div>

<!-- 展示图片大小 -->
<style type="text/css">
    .layui-table-cell {
        text-align: center;
        height: auto;
        white-space: normal;
    }

    .layui-table img {
        max-width: 100px
    }
</style>


<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv">
    <form class="layui-form " action="" lay-filter="dataFrm" id="dataFrm">


        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">快递公司：</label>
                <div class="layui-input-block">
                    <select name="data_id" id="data_id" lay-filter="data_id">
                        <option value=""></option>
                        {% for j in delivery %}
                            <option value="{{ j.id }}">{{ j.name }}</option>
                        {% endfor %}

                    </select>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">快递单号：</label>
                <div class="layui-input-block">
                    <input type="text" name="logistics_num" placeholder="请输入快递单号" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>


{#        <input type="hidden" name="order_id" id="order_id" value="{{ order_id }}">#}
        <input type="hidden" name="status" value="{{ status }}">
        <input type="hidden" name="user_id_" value="{{ user_id or '' }}">

        <div class="layui-form-item" style="margin-top:40px; ">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="doSubmit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>


    </form>
</div>
<!-- 添加和修改的弹出层结束 -->


<script src="{{ url_for('static',filename='layuiadmin/layui/layui.js') }}"></script>
<script>
    layui.config({
        base: '../../../static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'jquery', 'layer', 'form', 'upload'], function () {
        var admin = layui.admin;
        var table = layui.table;
        var upload = layui.upload;
        var $ = layui.jquery;
        var data_status = $("input[name='status']").val();
        var data_user_id = $("input[name='user_id_']").val();
        var tableIns = table.render({
            elem: '#test-table',
            title: '全部订单',
            toolbar: true,
            url: '/cms/mall/back_orders_info/?status=' + data_status + '&user_id=' + data_user_id,
            cols: [[
                {type: 'checkbox'},
                {field: 'order_goods_id', title: 'ID', align: 'center', hide: true,},
                {field: 'phone', title: '账号', align: 'center'},
                {field: 'trade_no', title: '订单号', align: 'center'},
                {field: 'goods_name', title: '商品名称', align: 'center'},
                {field: 'goods_num', title: '数量', align: 'center'},
                {field: 'price', title: '单价', align: 'center'},
                {field: 'total_price', title: '总金额', align: 'center'},
                {#{field: 'freight', title: '运费', align: 'center'},#}
                {field: 'actual_one', title: '实付单价', align: 'center'},
                {field: 'actual_price', title: '实付金额', align: 'center'},
                {field: 'refunds_num', title: '退款数量', align: 'center'},
                {field: 'refunds_price', title: '退款价格', align: 'center'},
                {field: 'logistics_name', title: '物流公司', align: 'center'},
                {field: 'logistics_num', title: '物流单号', align: 'center'},
                {field: 'back_status_str', title: '退货状态', align: 'center'},
                {field: 'status_str', title: '状态', align: 'center'},
            ]]
            , page: true
        });


        var active = {
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('test-table'),
                    data = checkStatus.data;

                var dict_data = {'order_list': JSON.stringify(data)};
                dict_data['btn_status'] = 0;
                layer.confirm('您确定要成功么?', function (index) {
                    $.ajax({
                        url: '/cms/mall/update_orders_goods_status/',
                        type: "POST",
                        {#data: JSON.stringify(data),#}
                        data: JSON.stringify(dict_data),
                        success: function (data) {
                            if (data['code'] == 200) {
                                layer.msg("成功", {icon: 6});
                                tableIns.reload()
                            } else {
                                layer.msg(data['message'], {icon: 5});
                            }
                        }
                    });
                });
            }
            , getCheckLength: function () { //获取选中数目
                var checkStatus = table.checkStatus('test-table'),
                    data = checkStatus.data;
                var dict_data = {'order_list': JSON.stringify(data)};
                dict_data['btn_status'] = 1;
                layer.confirm('您确定要失败么?', function (index) {
                    $.ajax({
                        url: '/cms/mall/update_orders_goods_status/',
                        type: "POST",
                        data: JSON.stringify(dict_data),
                        success: function (data) {
                            if (data['code'] == 200) {
                                layer.msg("成功", {icon: 6});
                                tableIns.reload()
                            } else {
                                layer.msg(data['message'], {icon: 5});
                            }
                        }
                    });
                });
            }

        };

        $('.check-layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.check-cancel-layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
</body>
</html>